package com.qdlc.p2p.biz.processor.task;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.qdlc.p2p.biz.processor.event.NoticeValueEvent;
import com.qdlc.p2p.common.constant.Global;
import com.qdlc.p2p.common.core.queue.TaskProcessorException;
import com.qdlc.p2p.common.core.queue.ValueEvent;
import com.qdlc.p2p.common.util.DateUtil;
import com.qdlc.p2p.dal.dao.MessageDao;
import com.qdlc.p2p.dal.dao.NoticeDao;
import com.qdlc.p2p.dal.dto.Message;
import com.qdlc.p2p.dal.dto.Notice;

/**
 * 发送站内信息
 * @author linya 2016-01-17
 */
@Service
public class NoticeMessageTaskProcessor extends AbstractTaskProcessor {

	@Resource
	MessageDao messageDao;
	
	@Resource
	NoticeDao noticeDao;
	
	@Override
	public boolean supports(ValueEvent event) {
		return event instanceof NoticeValueEvent;
	}

	@Override
	protected void process0(ValueEvent event) throws TaskProcessorException {
        NoticeValueEvent messageEvent = (NoticeValueEvent) event;
		Notice s = messageEvent.getNotice();
		Message m = new Message();
        m.setTitle(s.getTitle());
        m.setSentUserId(s.getSentUserId());
        m.setReceiveUserId(s.getReceiveUserId());
        m.setContent(s.getContent());
        m.setAddTime(DateUtil.getNow());
        m.setAddIp(Global.getIP());
        messageDao.insert(m);
        s.setStatus(1);
        s.setResult("ok");
        noticeDao.save(s);
	}

}
